import wx

class icon(wx.TaskBarIcon):
	def __init__(self, parent, icon, tooltip):
		wx.TaskBarIcon.__init__(self)
		self.SetIcon(icon, tooltip)
		self.parent = parent
		self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnLeftDClick)
		self.CreateMenu()
		self.show = False

	def CreateMenu(self):
		ID_PREFERENCES_OPTION = wx.NewId()
		ID_TWEET_SONG = wx.NewId()
	
		self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnPopup)
		self.menu = wx.Menu()
		self.menu.Append(ID_PREFERENCES_OPTION, '&Preferences')
		self.menu.Append(ID_TWEET_SONG, '&Tweet this Song')
		self.menu.AppendSeparator()
		self.menu.Append(wx.ID_EXIT, 'E&xit')
		
		self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
		self.Bind(wx.EVT_MENU, self.OnPreferences, id=ID_PREFERENCES_OPTION)
		self.Bind(wx.EVT_MENU, self.OnTweetSong, id=ID_TWEET_SONG)

	def OnPopup(self, event):
		self.PopupMenu(self.menu)

	def OnLeftDClick(self, event):
		if not self.parent.IsShown():
			self.parent.Raise()

	def OnExit(self, event):
		self.parent.Close(True)
		self.Destroy()
		
	def OnPreferences(self, event):
		if not self.parent.IsShown():
			self.parent.Raise()

	def OnTweetSong(self, event):
		self.parent.core.playback_current_id(self.parent.core.onTweetSong)
		
